﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyOA.Model;
using System.Data.SqlClient;
using System.Data;

namespace MyOA.DAL
{
    public class RoleInfoService
    {
        DBHelper db = new DBHelper();
        //根据roleId查找RoleInfo信息
        public RoleInfo GetRoleInfoByRoleId(int roleId)
        {
            RoleInfo roleInfo = new RoleInfo();
            using (SqlDataReader reader = db.getDataReader("proc_getRoleInfoByRoleId", new SqlParameter("@roleId", roleId)))
            {
                if (reader.Read())
                {
                    roleInfo.RoleId = (int)reader["RoleId"];
                    roleInfo.RoleName = (string)reader["RoleName"];
                    reader.Close();
                }
                db.CloseConnection();
                return roleInfo;
            }
        }
        //查找所有RoleInfo信息
        public IList<RoleInfo> GetAllRoleInfo()
        {
            List<RoleInfo> roleInfoList = new List<RoleInfo>();
            using (DataTable table = db.getDataTable("proc_getAllRoleInfo"))
            {
                foreach (DataRow row in table.Rows)
                {
                    RoleInfo roleInfo = new RoleInfo();
                    roleInfo.RoleId = (int)row["RoleId"];
                    roleInfo.RoleName = (string)row["RoleName"];
                    roleInfoList.Add(roleInfo);
                }
                return roleInfoList;
            }
        }
    }
}
